package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabFeeItem;
import com.ysd.lis.entity.lab.LabRptBanFeeitem;
import com.ysd.lis.mapper.lab.LabFeeItemMapper;
import com.ysd.lis.mapper.lab.LabRptBanFeeitemMapper;
import com.ysd.lis.request.DeleteRptVsBarCodeParam;
import com.ysd.lis.service.lab.LabRptBanFeeitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wh
 * @since 2025-02-20
 */
@Service
public class LabRptBanFeeitemServiceImpl extends ServiceImpl<LabRptBanFeeitemMapper, LabRptBanFeeitem> implements LabRptBanFeeitemService {

    @Autowired
    private LabFeeItemMapper labFeeItemMapper;

    @Override
    public Result findBanFeeListByRptGroup(String rptGroup) {

        Assert.hasText(rptGroup, "rptGroup must not be empty");
        MPJLambdaWrapper<LabFeeItem> mpjLambdaWrapper = new MPJLambdaWrapper<>();
        mpjLambdaWrapper
                .selectAll(LabFeeItem.class)
                .selectAs(LabRptBanFeeitem::getId, LabFeeItem::getRptBanFeeItemId)
                .leftJoin(LabRptBanFeeitem.class, LabRptBanFeeitem::getFeeCode, LabFeeItem::getFeeCode)
                .eq(LabRptBanFeeitem::getRptGroup, rptGroup)
                .eq(LabFeeItem::getDelFlag, 0)
                .eq(LabRptBanFeeitem::getDelFlag, 0);
        List<LabFeeItem> feeItemList = labFeeItemMapper.selectList(mpjLambdaWrapper);
        return Result.succ(1, "查询成功", feeItemList);
    }

    @Override
    public Result addBanFeeeItem(LabRptBanFeeitem labRptBanFeeitem) {
        boolean save = this.saveOrUpdate(labRptBanFeeitem, new LambdaQueryWrapper<LabRptBanFeeitem>().eq(LabRptBanFeeitem::getRptGroup, labRptBanFeeitem.getRptGroup()).eq(LabRptBanFeeitem::getFeeCode, labRptBanFeeitem.getFeeCode()).eq(LabRptBanFeeitem::getDelFlag, 0));
        if (save) {
            return Result.succ(1, "", null);
        } else {
            return Result.fail("添加失败！");
        }
    }

    @Override
    public Result deleteBanFeeItem(DeleteRptVsBarCodeParam deleteRptVsBarCodeParam) {
        int i = this.baseMapper.deleteById(deleteRptVsBarCodeParam.getId());
        if (i > 0) {
            return Result.succ(1, "删除成功", null);
        } else {
            return Result.fail("删除失败！");
        }
    }
}
